package com.changan.service.impl;

import com.changan.vo.LoginVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.changan.entity.User;
import com.changan.mapper.UserMapper;
import com.changan.service.UserService;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class UserServiceImpl implements UserService{

    @Resource
    private UserMapper userMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(User record) {
        return userMapper.insert(record);
    }

    @Override
    public int insertSelective(User record) {
        return userMapper.insertSelective(record);
    }

    @Override
    public User selectByPrimaryKey(Long id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return userMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(User record) {
        return userMapper.updateByPrimaryKey(record);
    }

    @Override
    public User login(String userCode) {
        User user = userMapper.loadUserByUserCode(userCode);
        return user;
    }

    @Override
    public PageInfo<User> getUsersByPage(Integer pageNum, Integer pageSize, String userName, Integer userRole) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> users = userMapper.getUsers(userName, userRole);
        PageInfo<User> pageInfo = new PageInfo<>(users);
        return pageInfo;
    }

}
